
package com.sbtr.business.calibration.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbtr.business.calibration.entity.CalibrationFile;
import com.sbtr.business.calibration.mapper.CalibrationFileMapper;
import com.sbtr.business.calibration.service.ICalibrationFileService;
import com.sbtr.open.calibration.dto.CalibrationFileDto;
import com.sbtr.util.BeanCopyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 标定集 服务实现类
 * </p>
 *

 */
@Transactional
@Service
public class CalibrationFileServiceImpl extends ServiceImpl<CalibrationFileMapper, CalibrationFile>
		implements ICalibrationFileService {


	private static final Logger logger = LoggerFactory.getLogger(CalibrationFileServiceImpl.class);

	@Override
	public CalibrationFileDto save(CalibrationFileDto dto) {
		CalibrationFile data = BeanCopyUtils.copyProperties(dto, CalibrationFile.class);
		if(dto.getId() == null) {
			save(data);
			dto.setId(data.getId());
		}else {
			return BeanCopyUtils.copyProperties(data, CalibrationFileDto.class);
		}
		return dto;
	}

	@Override
	public CalibrationFileDto findById(Long id) {
		return BeanCopyUtils.copyProperties(getById(id), CalibrationFileDto.class);
	}

	@Override
	public CalibrationFileDto findByCalibrationId(Long calibrationId) {

		QueryWrapper<CalibrationFile> query = new QueryWrapper<>();
		query.eq("calibration_id",calibrationId);

		CalibrationFile calibrationFile = this.baseMapper.selectList(query).get(0);

		return BeanCopyUtils.copyProperties(calibrationFile,CalibrationFileDto.class);
	}


}